package cn.tansanqinger.dao.sql.chatroom;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.tansanqinger.dao.sql.IGroupSqlDao;
import cn.tansanqinger.pojo.Flick;

@Repository
public class GroupSqlDaoImpl {

	@Autowired
	private IGroupSqlDao dao;
	
	/**
	 * 查询用户好友
	 * @param grade
	 * @return
	 */
	public List<Flick> selectMessage(int gid){
		QueryWrapper<Flick> queryWrapper = new QueryWrapper<Flick>();
		queryWrapper.lambda().eq(Flick::getGid, gid);
		return dao.selectList(queryWrapper);
	}
	
	/**
	 * 通过群号查询数据
	 * @param gsnGroup
	 * @return
	 */
	public Flick selectGroupOne(int gsnGroup) {
		QueryWrapper<Flick> queryWrapper = new QueryWrapper<Flick>();
		queryWrapper.lambda().eq(Flick::getGsn, gsnGroup);
		return dao.selectById(1);
	}
	
	/**
	 * 获取编号
	 * @return
	 */
	public Integer serialNumber() {
		QueryWrapper<Flick> queryWrapper = new QueryWrapper<Flick>();
		queryWrapper.orderByDesc("gsnGroup").last("limit 1");
		Flick object = dao.selectOne(queryWrapper);
		return object==null?10000001:object.getGsn()+1;
	}
	
	/**
	 * 添加信息
	 * @param course
	 * @return
	 */
	public int add(Flick object) {
		return dao.insert(object);
	}
	
	/**
	 * 查询信息
	 * @param cid
	 * @return
	 */
	public Flick selectOnt(int id) {
		return dao.selectById(id);
	}
	
	/**
	 * 修改状态
	 * @param cid
	 * @param isuse
	 * @return
	 */
	public int updateStatus(Flick object) {
		return dao.updateById(object);
	}
	
	/**
	 * 删除信息
	 * @param cid
	 * @return
	 */
	public int deleteOne(int id) {
		return dao.deleteById(id);
	}
	
	/**
	 * 修改信息
	 * @param user
	 * @return
	 */
	public int modification(Flick object) {
		return dao.updateById(object);
	}
	
}
